package com.ruoyi.web.controller.okr;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.OkrInform;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IOkrInformService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by Bruce on 2021/8/16 11:23
 **/
@Controller
@RequestMapping("/inform")
public class MyOkrInformController extends BaseController {
    @Autowired
    private IOkrInformService okrInformService;

    private String prefix = "okr";

    @GetMapping("")
    public String showInform(){
        return prefix + "/okrInform";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo selectInformByUserId(){
        SysUser user = ShiroUtils.getSysUser();
        List<OkrInform> okrInforms = okrInformService.selectInformByUserId(user.getUserId());
        return getDataTable(okrInforms);
    }

    @RequestMapping("/getInformList")
    @ResponseBody
    public List<OkrInform> getInformList(){
        SysUser user = ShiroUtils.getSysUser();
        List<OkrInform> okrInforms = okrInformService.selectInformByUserId(user.getUserId());
        return okrInforms;
    }

    @PostMapping("/confirm")
    @ResponseBody
    public AjaxResult confirmInform(@Param("id") Long id){
        okrInformService.deleteInformById(id);
        return AjaxResult.success("确认并删除通知");
    }
}
